package com.winsafe.scanlibrary;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;

public class HoneywellScanResultReceiver extends BroadcastReceiver {
    public static final int READ_RESULT = 991;

    private Handler mHandler;

    /**
     * 入库管理-两个模块扫描事件接收者 修改
     *
     * @param handler
     */
    public void reset(Handler handler) {
        this.mHandler = handler;
    }

    public HoneywellScanResultReceiver(Handler handler) {
        this.mHandler = handler;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (HoneywellScannerInterface.ACTION_BARCODE_DATA.equals(intent.getAction())) {
            int version = intent.getIntExtra("version", 0);
            if (version >= 1) {
                String data = intent.getStringExtra("data");
                mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, data));
            } else {
                mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, ""));
            }
        } else {
            mHandler.sendMessage(Message.obtain(mHandler, READ_RESULT, ""));
        }
    }

    @SuppressWarnings("unused")
    private String bytesToHexString(byte[] arr) {
        String s = "[]";
        if (arr != null) {
            s = "[";
            for (int i = 0; i < arr.length; i++) {
                s += "0x" + Integer.toHexString(arr[i]) + ", ";
            }
            s = s.substring(0, s.length() - 2) + "]";
        }
        return s;
    }
}
